﻿using System;
using System.Linq;
using Tasks247.Data;
using Tasks247.Model;

namespace Tasks247.Views
{
    public class UpdateTaskView
    {
        public UpdateTaskView(ITasksRepository repository)
        {
            TaskEntity taskToUpdate = repository.Read().FirstOrDefault();
            if (taskToUpdate != null)
            {
                repository.Update(taskToUpdate);
                Console.WriteLine("{0},{1},{2}", "Id".PadLeft(10), "Name".PadLeft(20));
                Console.WriteLine("{0},{1}", taskToUpdate.Id.ToString().PadLeft(10), taskToUpdate.Name.PadLeft(20));
                Console.WriteLine("Notes: {0}", taskToUpdate.Notes.PadLeft(30));
            }
            else
            {
                Console.WriteLine("No records to update...");
            }
        }
    }
}